﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIS.SDK.Api.Response;
using AIS.SDK.Common;
using AIS.SDK.Model;
using Newtonsoft.Json;

namespace AIS.SDK.Api.Requests
{
    public  class FormserviceV2 : ApiRequest<FormserviceResponse>
    {
        public FormserviceV2(FormRequest request,string _token,string _devicename)
        {
            Frequest = request;
            token = _token;
            devicename = _devicename;
            Frequest.token = _token;
        }

        public FormRequest Frequest { get; set; }

        public string token { get; set; }
        public string devicename { get; set; }

        internal override string Method
        {
            get { return "POST"; }
        }

        protected override string UrlFormat
        {
            get { return "/formservice"; }
        }

        internal override string GetUrl()
        {
            return GlobalVariables.GetAISServerUrl() + UrlFormat;
        }

        protected override bool NeedToken
        {
            get { return true; }
        }

        internal override void Validate()
        {
            if (Frequest == null)
            {
                throw new ArgumentNullException("Request Is null");
            }
        }

        public override string GetPostContent()
        {
            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore

            };
         
            return JsonConvert.SerializeObject(Frequest, settings);
        }


        public override Dictionary<string, string> Headers()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            if (!string.IsNullOrWhiteSpace(devicename))
            {
                dic.Add("jde-AIS-Auth-Device", devicename);
            }
            if (!string.IsNullOrWhiteSpace(token))
            {
                dic.Add("jde-AIS-Auth", token);
            }
            
            return dic;
        }
    }
}
